@echo off
echo Debugging Git Tag Functionality
echo =============================

REM 检查当前git状态
echo Current git status:
git status --porcelain

echo.
echo Current git tags:
git tag

echo.
set /p version_number=Enter test version number (e.g., 1.9.9): 

REM 检查标签是否已存在
echo Checking if tag v%version_number% exists...
git tag --list | findstr "v%version_number%" >nul
if %errorlevel% equ 0 (
    echo Tag v%version_number% already exists
    set /p delete_tag=Delete existing tag? (y/n): 
    if /i "%delete_tag%"=="y" (
        echo Deleting tag v%version_number%...
        git tag -d v%version_number%
        git push origin --delete v%version_number%
    ) else (
        echo Keeping existing tag
        goto :end
    )
) else (
    echo Tag v%version_number% does not exist
)

REM 创建测试标签
echo Creating tag v%version_number%...
git tag -a v%version_number% -m "Debug test tag v%version_number%"

if %errorlevel% neq 0 (
    echo Error: Failed to create tag
    echo Error level: %errorlevel%
    goto :end
)

echo Tag created successfully

REM 推送标签
echo Pushing tag to remote...
git push origin v%version_number%

if %errorlevel% neq 0 (
    echo Error: Failed to push tag
    echo Error level: %errorlevel%
    goto :end
)

echo Tag pushed successfully

:end
echo.
echo Debug script completed
pause